<template>
  <section class="build-show-room-detail">
    <div class="qup-page-heade bread-box">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item class="btn-green" @click.native="goBack(false)">小区样板间建设任务管理</el-breadcrumb-item>
        <el-breadcrumb-item>{{ title }}</el-breadcrumb-item>
      </el-breadcrumb>
      <div>
        <el-button size="mini" @click.native="goBack(false)">返回</el-button>
        <el-button v-if="flag!=='view'" size="mini" type="primary" @click.native="confirm">确认</el-button>
      </div>
    </div>
    <section v-loading="loading">
      <ConsComp title="楼盘签约信息">
        <template v-slot:content>
          <el-form ref="signingForm" :model="form.signingRealEstateDTO" :rules="rules" label-width="100px">
            <el-row :gutter="0">
              <el-col v-for="item in signInfoList" :key="item.label" :span="8">
                <el-form-item
                  :label="item.label+':'"
                  :rules="[
                    { required: form.signingRealEstateDTO[item.linkId] == true||item.required, message: '请选择所属签约楼盘', trigger: 'change' }]"
                  :prop="item.field"
                  :required="item.linkId?(form.signingRealEstateDTO[item.linkId] == true||item.required):item.required"
                >
                  <el-select
                    v-if="item.type==='select'"
                    v-model="form.signingRealEstateDTO[item.field]"
                    :disabled="flag==='view'"
                    style="width:100%;"
                  >
                    <el-option
                      v-for="op in item.opt"
                      :key="op.val"
                      :label="op.label"
                      :value="op.val"
                    />
                  </el-select>
                  <input-with-dialog
                    v-if="item.type==='inpWDialog'"
                    v-model="form.signingRealEstateDTO.realEstateConItem"
                    :disabled="flag==='view'"
                    :props="{label:'realEstateContractNumber',value:'realEstateContractNumber'}"
                    :focus-query="true"
                    :config="{
                      title:item.label,
                      width:'600px',
                      interfacePath:item.url,
                      method:'POST',
                      paramField:'keyWord',
                      filtersRaw:item.filter,
                      paramsRaw:{},
                      setting:item.setting
                    }"
                    @change="realEstateConChange"
                  />
                  <span v-if="item.type==='match'">{{ item.opt[form.signingRealEstateDTO[item.field]] }}</span>
                  <span v-if="item.type=='txt'">{{ form.signingRealEstateDTO[item.field] }}</span>
                  <span v-if="item.type=='dict'">{{ matchDict(item.dictType,form.signingRealEstateDTO[item.field]) }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
      <ConsComp title="小区样板间信息">
        <template v-slot:content>
          <el-form ref="roomForm" :model="form.modelRoomInfoDTO" :rules="rules" label-width="128px">
            <el-row :gutter="0">
              <el-col v-for="item in showRoomList" :key="item.label" :span="item.cols||8">
                <el-form-item :label="item.label+':'" :required="item.required">
                  <p v-if="item.type==='file'" class="file-p">
                    <fileUploader
                      :data="matchFile(form.modelRoomInfoDTO[item.field])"
                      :limit="1"
                      :show-download-temp="false"
                      :show-edit="false"
                      :show-remove="false"
                      :show-upload="false"
                    >
                      <template #downloadBtn="file">
                        <a
                          v-if="isHttp(file.file.attachmentUrl)"
                          class="option-icon link-item"
                          @click="downLoadFileFn(file.file)"
                        >
                          <i class="el-icon-download" />
                        </a>
                        <a
                          v-else
                          class="option-icon link-item"
                          :href="file.attachmentUrl"
                          :download="matchFileName(file)"
                        >
                          <i class="el-icon-download" />
                        </a>
                      </template>
                    </fileUploader>
                    <!-- <el-link type="primary" @click="fileView(form.modelRoomInfoDTO[item.field])">{{ matchFileName(form.modelRoomInfoDTO[item.field]) }}</el-link>
                    <a v-if="form.modelRoomInfoDTO[item.field]" :href="form.modelRoomInfoDTO[item.field]">
                      <svg-icon icon-class="xiazai" class-name="xiazaiIcon" />
                    </a> -->
                  </p>
                  <span v-if="item.type==='match'">{{ item.opt[form.modelRoomInfoDTO[item.field]] }}</span>
                  <span v-if="item.type=='txt'">{{ form.modelRoomInfoDTO[item.field] }}</span>
                  <span v-if="item.type=='dict'">{{ matchDict(item.dictType,form.modelRoomInfoDTO[item.field]) }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
      <ConsComp title="小区样板间订单信息">
        <template v-slot:content>
          <table-box
            no-request
            :table-height="220"
            :table-sortable="false"
            :table-config="tableConfig"
            :show-custom-setting="false"
            :data="form.modelRoomOrderDTO"
          >
            <el-table-column slot="before" label="序号" width="50" align="center" type="index" />
          </table-box>
        </template>
      </ConsComp>
      <ConsComp title="小区样板间验收信息">
        <template v-slot:content>
          <el-form ref="acceptForm" :model="form.modelRoomAcceptanceDTO" :rules="rules" label-width="170px">
            <el-row :gutter="0">
              <el-col v-for="item in checkInfoList" :key="item.label" :span="item.cols||8">
                <el-form-item v-if="!item.linkId" :label="item.label+':'" :required="item.required">
                  <p v-if="item.type==='file'" class="file-p">
                    <fileUploader
                      :data="matchFile(form.modelRoomAcceptanceDTO[item.field])"
                      :limit="1"
                      :show-download-temp="false"
                      :show-edit="false"
                      :show-remove="false"
                      :show-upload="false"
                    >
                      <template v-slot:downloadBtn>
                        <a
                          v-if="isHttp(form.modelRoomAcceptanceDTO[item.field])"
                          class="option-icon link-item"
                          @click="downLoadFileFn(matchFile(form.modelRoomAcceptanceDTO[item.field]))"
                        >
                          <i class="el-icon-download" />
                        </a>
                        <a
                          v-else
                          class="option-icon link-item"
                          :href="form.modelRoomAcceptanceDTO[item.field]"
                          :download="matchFileName(form.modelRoomAcceptanceDTO[item.field])"
                        >
                          <i class="el-icon-download" />
                        </a>
                      </template>
                    </fileUploader>
                  </p>
                  <span v-if="item.type=='txt'">{{ form.modelRoomAcceptanceDTO[item.field] }}</span>
                  <span v-if="item.type==='match'">{{ item.opt[form.modelRoomAcceptanceDTO[item.field]] }}</span>
                  <span v-if="item.type=='dict'">{{ matchDict(item.dictType,form.modelRoomAcceptanceDTO[item.field]) }}</span>
                </el-form-item>
                <el-form-item v-else-if="!form.modelRoomAcceptanceDTO[item.linkId]" :label="item.label">
                  <span>{{ form.modelRoomAcceptanceDTO[item.field] }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
      <ConsComp title="小区样板间返利信息">
        <template v-slot:content>
          <el-form ref="rebateForm" :model="form.modelRoomRebateDTO" :rules="rules" label-width="170px">
            <el-row :gutter="0">
              <el-col v-for="item in feedbackInfoList" :key="item.label" :span="item.cols||8">
                <el-form-item :label="item.label+':'" :required="item.required">
                  <span v-if="item.type==='match'">{{ item.opt[form.modelRoomRebateDTO[item.field]] }}</span>
                  <span v-if="item.type=='txt'">{{ form.modelRoomRebateDTO[item.field] }}</span>
                  <span v-if="item.type=='dict'">{{ matchDict(item.dictType,form.modelRoomRebateDTO[item.field]) }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </ConsComp>
    </section>
    <el-image-viewer
      v-if="showViewer"
      :on-close="closeViewer"
      :url-list="urlList"
    />
  </section>
</template>

<script>
import { getDictByPatchType } from '@/api/dataDict'
import BackPageMixin from '@/mixins/backPage'
import ConsComp from '../../components/consComp'
import { downloadFile } from '@/api/common.js'
import fileUploader from '@/components/importFile/FileUploader'
import { modelRoomInfo, putModelRoomInfo, configSeries } from '@/api/showRoomInfo'
export default {
  components: {
    ConsComp,
    fileUploader
  },
  mixins: [BackPageMixin],
  props: {
    flag: {// 控制页面状态  新增、编辑、详情
      type: String,
      default() {
        return 'new'
      }
    },
    row: {
      type: [Array, Object],
      default() {
        return []
      }
    }
  },
  data() {
    const _this = this
    return {
      loading: false,
      showViewer: false,
      urlList: [],
      fileTypeList: [],
      signInfoList: [
        {
          label: '样板间任务编码',
          field: 'modelRoomTaskCode',
          type: 'txt',
          required: false
        }, {
          label: '样板间任务名称',
          field: 'modelRoomTaskName',
          type: 'txt',
          required: false
        }, {
          label: '是否签约楼盘',
          field: 'isSigningRealEstate',
          type: 'select',
          opt: [{ label: '否', val: 0 }, { label: '是', val: 1 }],
          required: true
        }, {
          label: '所属签约楼盘',
          field: 'realEstateContractNumber',
          type: 'inpWDialog',
          url: `${process.env.VUE_APP_BASE_API}/api/v1/signingRealEstate/page`,
          filter: [{ 'id': 'enable', 'property': 'enable', 'operator': '=', 'value': '1' }],
          linkId: 'isSigningRealEstate',
          setting: [
            { prop: 'realEstateContractNumber', title: '编码', width: 80 },
            { prop: 'communityName', title: '名称' }]
        }, {
          label: '小区名称',
          field: 'communityName',
          type: 'txt',
          required: false
        }, {
          label: '小区详细地址',
          field: 'communityAddress',
          type: 'txt',
          required: false
        }, {
          label: '交房日期',
          field: 'houseDeliveryTime',
          type: 'txt',
          required: false
        }, {
          label: '楼盘装修类型', // DECORATION_TYPE
          field: 'roomDecorateType',
          type: 'dict',
          dictType: 'DECORATION_TYPE',
          required: false
        }, {
          label: '交房户数',
          field: 'deliveryModelRoomNumber',
          type: 'txt',
          required: false
        }, {
          label: '客户',
          field: 'customerCode',
          type: 'txt',
          required: false
        }, {
          label: '客户名称',
          field: 'customerName',
          type: 'txt',
          required: false
        }, {
          label: '所属办事处',
          field: 'agencyName',
          type: 'txt',
          required: false
        }, {
          label: '办事处性质',
          field: 'agencyNature',
          type: 'dict',
          dictType: 'OFFICE_NATURE',
          required: false
        }, {
          label: '市场级别',
          field: 'marketLevel',
          type: 'dict',
          dictType: 'CITY_LEVEL',
          required: false
        }, {
          label: '成品客户经理',
          field: 'finishedProductCustomerManagerName',
          type: 'txt',
          required: false
        }, {
          label: '定制客户经理',
          field: 'customCustomerManagerName',
          type: 'txt',
          required: false
        }, {
          label: '提报月份',
          field: 'submissionDate',
          type: 'txt',
          required: false
        }, {
          label: '数据来源',
          field: 'dataSource',
          type: 'match',
          opt: {
            0: 'BPM',
            1: '手工创建'
          },
          required: false
        }, {
          label: '启用状态',
          field: 'enable',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '创建人',
          field: 'submitterName',
          type: 'txt',
          required: false
        }, {
          label: '创建时间',
          field: 'createTime',
          type: 'txt',
          required: false
        }, {
          label: '提报人',
          field: 'submitterName',
          type: 'txt',
          required: false
        }
      ],
      showRoomList: [
        {
          label: '样板间楼栋号',
          field: 'storiedBuildingNumber',
          type: 'txt',
          required: false
        }, {
          label: '样板间建设进度',
          field: 'modelRoomBuildSchedule', // YBJ_CONSTRUCTION_STEP
          type: 'dict',
          dictType: 'YBJ_CONSTRUCTION_STEP',
          required: false
        }, {
          label: '样板间运营状态',
          field: 'modelRoomOperateState', // YBJ_OPERATION_STATUS
          type: 'dict',
          dictType: 'YBJ_OPERATION_STATUS',
          required: false
        }, {
          label: '样板间类型',
          field: 'modelRoomType', // YBJ_TYPE
          type: 'dict',
          dictType: 'YBJ_TYPE',
          required: false
        }, {
          label: '样板间申请类型',
          field: 'modelRoomApplyType', // YBJ_APPLY_TYPE
          type: 'dict',
          dictType: 'YBJ_APPLY_TYPE',
          required: false
        }, {
          label: '产品品类',
          field: 'productType',
          type: 'dict',
          dictType: 'YBJ_PRO_CATEGARY',
          required: false
        }, {
          label: '样板间建设BPM单号',
          field: 'bpmNumber',
          type: 'txt',
          required: false
        }, {
          label: '样板间总面积',
          field: 'modelRoomTotalArea',
          type: 'txt',
          required: false
        }, {
          label: '饰品预计提货时间',
          field: 'decorationPredictDeliveryTime',
          type: 'txt',
          required: false
        }, {
          label: '饰品配置方案',
          field: 'decorationAllocationPlan',
          type: 'dict',
          dictType: 'ALLOCATION_PLAN',
          required: false
        }, {
          label: '店面设计负责人',
          field: 'headOfStoreDesignName',
          type: 'txt',
          required: false
        }, {
          label: '店面设计负责人电话',
          field: 'headOfStoreDesignPhone',
          type: 'txt',
          required: false
        }, {
          label: '饰品开单账号',
          field: 'decorationOrderAccount',
          type: 'txt',
          required: false
        }, {
          label: '账号名称',
          field: 'decorationOrderAccountName',
          type: 'txt',
          required: false
        }, {
          label: '送达方编码',
          field: 'servingPartyCode',
          type: 'txt',
          required: false
        }, {
          label: '送达方名称',
          field: 'servingPartyName',
          type: 'txt',
          required: false
        }, {
          label: '业主姓名',
          field: 'ownerName',
          type: 'txt',
          required: false
        }, {
          label: '业主联系电话',
          field: 'ownerPhone',
          type: 'txt',
          required: false
        }, /*  {
          label: '特殊情况说明',
          field: 'specialSituationExplain',
          type: 'txt',
          cols: 24,
          required: false
        }, */ {
          label: '申请人',
          field: 'applicantName',
          type: 'txt',
          required: false
        }, {
          label: '申请人类型',
          field: 'applicantType', // PROPOSER_TYPE
          type: 'dict',
          dictType: 'PROPOSER_TYPE',
          required: false
        }, {
          label: '申请时间',
          field: 'applicantTime',
          type: 'txt',
          required: false
        }, {
          label: '设计资料附件',
          field: 'designDataAnnex',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '样板间项目验收表',
          field: 'businessCallBackOpinionFileUrl',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '调整后设计方案附件',
          field: 'modifyAfterDesignDataAnnex',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '饰品配置方案附件',
          field: 'decorationAllocationPlanAccessory',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '减免后饰品配置方案附件',
          field: 'reducedOrnamentPlanFileUrls',
          type: 'file',
          cols: 24,
          required: false
        }
      ],
      checkInfoList: [
        /* {
          label: '样板间是否开始运营',
          field: 'isOperation',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, */ {
          label: '样板间实际运营时间（起）',
          field: 'realOperationStartTime',
          type: 'txt',
          required: false
        }, {
          label: '样板间实际运营时间（止）',
          field: 'realOperationEndTime',
          type: 'txt',
          required: true
        }, {
          label: '验收申请说明',
          field: 'acceptanceApplyForInstruction',
          type: 'txt',
          cols: 16,
          required: false
        }, {
          label: '验收流程单号',
          field: 'acceptanceProcessNumber',
          type: 'txt',
          required: false
        }, {
          label: '形象督导',
          field: 'supervisionImage',
          type: 'txt',
          required: false
        }, {
          label: '饰品是否已开单',
          field: 'isAccessoriesOrder',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '饰品是否有减免',
          field: 'isAccessoriesDerate',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '样板间户型',
          field: 'modelApartmentType',
          type: 'txt',
          required: false
        }, {
          label: '软装陈列是否合格',
          field: 'isSoftDecoraDisQualified',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '软装陈列评分',
          field: 'softDecoraDisScore',
          type: 'txt',
          required: false
        }, /* {
          label: '是否完成验收',
          field: 'isCompletionAcceptance',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, */ {
          label: '实际验收时间',
          field: 'actualAcceptanceTime',
          type: 'txt',
          required: false
        }, {
          label: '首次验收结果',
          field: 'firstAcceptanceResult',
          type: 'dict',
          dictType: 'YBJ_FIST_CHECK_RESULE',
          required: false
        }, {
          label: '整改结果',
          field: 'rectificationResult',
          type: 'dict',
          dictType: 'YBJ_RECTIFY_RESULE',
          required: false
        }, {
          label: '最终验收结果',
          field: 'finalAcceptanceResult',
          type: 'dict',
          dictType: 'YBJ_FINAL_CHECK_RESULE',
          required: false
        }, {
          label: '验收申请人',
          field: 'acceptanceApplicantName',
          type: 'txt',
          required: false
        }, {
          label: '验收申请时间',
          field: 'acceptanceApplicantTime',
          type: 'txt',
          required: false
        }, {
          label: '是否完成验收',
          field: 'isCompletionAcceptance',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '未完成验收原因',
          field: 'unCompletionAcceptanceMsg',
          linkId: 'isCompletionAcceptance',
          type: 'txt',
          required: false
        }, {
          label: '设计师软装审核通过时间',
          field: 'designerReviewTime',
          cols: 24,
          type: 'txt',
          required: false
        }, {
          label: '软装陈列附件',
          field: 'softOutfitDisplayFile',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '验收报告',
          field: 'acceptanceReportFile',
          type: 'file',
          cols: 24,
          required: false
        }, {
          label: '整改报告',
          field: 'rectificationReportFile',
          type: 'file',
          cols: 24,
          required: false
        }
      ],
      feedbackInfoList: [
        {
          label: '是否申请返利',
          field: 'isApplyRebate',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '返利审核结果',
          field: 'rebateAuditResult',
          type: 'dict',
          dictType: 'REVIEW_RESULT',
          required: true
        }, {
          label: '返利申请人AD账号',
          field: 'rebateApplicantCode',
          type: 'txt',
          required: false
        }, {
          label: '返利申请时间',
          field: 'rebateApplyTime',
          type: 'txt',
          required: false
        }, {
          label: '返利申请单号',
          field: 'rebateApplyNumber',
          type: 'txt',
          required: false
        }, {
          label: '返利申请人姓名',
          field: 'rebateApplicantName',
          type: 'txt',
          required: false
        }, {
          label: '返利申请类型',
          field: 'rebateType',
          cols: 24,
          type: 'dict',
          dictType: 'REBATE_TYPE',
          limit: true, // need  test limit
          required: false
        }, {
          label: '返利申报批次',
          field: 'rebateDeclarationBatch',
          type: 'txt',
          required: false
        }, {
          label: '返利申报说明',
          field: 'rebateApplyMsg',
          type: 'txt',
          cols: 24,
          required: false
        }, {
          label: '是否执行返利',
          field: 'isExecuteRebate',
          type: 'match',
          opt: {
            0: '否',
            1: '是'
          },
          required: false
        }, {
          label: '返利执行时间',
          field: 'rebateExecuteTime',
          type: 'txt',
          required: false
        }, {
          label: '不申请返利原因',
          field: 'notApplyRebateMsg',
          type: 'txt',
          cols: 24,
          required: false
        }, {
          label: '不执行返利原因',
          field: 'notExecuteRebateMsg',
          type: 'txt',
          cols: 24,
          required: false
        }, {
          label: '返利执行说明',
          field: 'executeRebateMsg',
          type: 'txt',
          cols: 24,
          required: false
        }
      ],
      rules: {
        realEstateConItem: [{ required: true, message: '请选择所属签约楼盘', trigger: 'change' }]
      },
      tableConfig: {
        hideSearchBar: true,
        sort: '',
        buttonGroupCode: 'no',
        interfacePath: '',
        setting: [
          {
            prop: 'orderType',
            label: '订单类型',
            align: 'left',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'YBJ_ORDER_TYPE'
            }
          },
          {
            prop: 'orderNumber',
            label: '接单编号',
            align: 'left'
          },
          {
            prop: 'salesSeries',
            label: '销售系列',
            align: 'left',
            formatData: ({ salesSeries }) => {
              return _this.matchSeries(salesSeries)
            }
          }]
      },
      allseries: [],
      form: {
        modelRoomOrderDTO: [],
        signingRealEstateDTO: {},
        modelRoomRebateDTO: {},
        modelRoomAcceptanceDTO: {}
      },
      dictMap: {},
      backtypeOpts: []
    }
  },
  computed: {
    title() {
      let title = '详情'
      if (this.flag === 'edit') {
        title = '编辑'
      }
      return title
    }
  },
  async created() {
    await this.getDictByPatchTypeAll()
    await this.getAllSeries()
    const queryId = this.row[0] ? this.row[0].id : this.row.id
    this.loading = true
    try {
      const data = await modelRoomInfo(queryId)
      this.matchForm(data)
      this.loading = false
    } catch (error) {
      this.loading = false
    }
  },
  methods: {
    async getAllSeries() {
      const { data } = await configSeries()
      this.allseries = data
    },
    matchSeries(series) {
      const seriesArr = series.split(',')
      const seriesItem = this.allseries.filter(item => seriesArr.includes(item.seriesCode))
      const seriesTxt = seriesItem.map(item => item.seriesName)
      return seriesTxt.join(',')
    },
    isHttp(file) {
      return file.indexOf('http') !== -1
    },
    async getDictByPatchTypeAll() {
      const dictRes = await getDictByPatchType(['CITY_LEVEL', 'YBJ_FINAL_CHECK_RESULE', 'YBJ_RECTIFY_RESULE', 'YBJ_FIST_CHECK_RESULE', 'REVIEW_RESULT', 'REBATE_TYPE', 'PROPOSER_TYPE', 'ALLOCATION_PLAN', 'YBJ_PRO_CATEGARY', 'YBJ_TYPE',
        'YBJ_APPLY_TYPE', 'YBJ_OPERATION_STATUS', 'YBJ_CONSTRUCTION_STEP', 'DECORATION_TYPE', 'OFFICE_NATURE'])
      this.$set(this, 'dictMap', dictRes)
    },
    matchForm(data) {
      for (const key in data) {
        const ele = data[key]
        this.$set(this.form, key, ele)
      }
      // 样板间信息取数据
      const acceptanceSub = ['supervisionImage', 'isAccessoriesOrder', 'isAccessoriesDerate',
        'modelApartmentType', 'isSoftDecoraDisQualified', 'softDecoraDisScore']
      for (let i = 0; i < acceptanceSub.length; i++) {
        const element = acceptanceSub[i]
        this.$set(this.form.modelRoomAcceptanceDTO, element, data.modelRoomInfoDTO[element])
      }
      // 样板间信息取数据
      const signingRealSub = ['modelRoomTaskName', 'modelRoomTaskCode', 'isSigningRealEstate']
      for (let i = 0; i < signingRealSub.length; i++) {
        const element = signingRealSub[i]
        this.$set(this.form.signingRealEstateDTO, element, data.modelRoomInfoDTO[element])
      }
      this.signInfoList.forEach(item => {
        if (item.field === 'realEstateContractNumber') {
          item.filter[1] = { property: 'customerCode', operator: '=', value: this.form.signingRealEstateDTO.customerCode }
        }
      })
      // 组装签约楼盘
      this.$set(this.form.signingRealEstateDTO, 'realEstateConItem', [{ realEstateContractNumber: data.signingRealEstateDTO.realEstateContractNumber }])
    },
    matchDict(type, val) {
      if (val == null || val == 'undefined') return ''
      const list = this.dictMap[type]
      // if (list === 'undefined') return
      const valArr = (val).toString().split(',')
      if (valArr.length > 1) {
        let str = ''
        for (let i = 0; i < valArr.length; i++) {
          const ele = valArr[i]
          const filterItem = list.filter(item => item.dictCode === ele)
          str += (filterItem[0] && filterItem[0].dictName || '') + ','
        }
        return str.substring(0, str.length - 1)
      }
      const filterItem = list.filter(item => item.dictCode === val)
      return filterItem[0] && filterItem[0].dictName || ''
    },
    matchFileName(path) {
      if (!path) return ''
      const pathArr = path.split('~')
      return pathArr[pathArr.length - 1]
    },
    matchFile(path) {
      if (!path) return []
      if (Array.isArray(path)) {
        const files = path.map(item => {
          const pathArr = item.split('~')
          return {
            attachmentName: pathArr[pathArr.length - 1],
            attachmentUrl: item,
            dr: 0
          }
        })
        return files
      }
      const pathArr = path.split('~')
      return [{
        attachmentName: pathArr[pathArr.length - 1],
        attachmentUrl: path,
        dr: 0
      }]
    },
    getFileData(file) {
      const t = {
        // file
        ...file,
        attachmentName: file.attachmentName || '',
        attachmentUrl: file.attachmentUrl || '',
        createBy: file.createBy || '',
        createTime: file.createTime || '',
        id: file.id || file.uid,
        typeName: file.typeName || (file.attachmentUrl || '').split('.').pop(),
        belongModel: file.belongModel || '',
        attachmentType: file.attachmentType || '',
        configAttachmentId: file.configAttachmentId || ''
      }
      delete t.raw
      return t
    },
    downLoadFileFn(files) {
      const file = this.getFileData(files[0] || files)
      let fileName = file.attachmentName
      if (fileName.replace(/(.*)\.(\w+)$/g, '$2') !== file.typeName.replace(/\.(\w+)$/, '$1')) {
        fileName = `${fileName}.${file.typeName.replace('.', '')}`
      }
      downloadFile(file.attachmentUrl).then(res => {
        const t = URL.createObjectURL(res)
        const a = document.createElement('a')
        a.href = t
        a.download = fileName
        a.click()
        setTimeout(() => {
          URL.revokeObjectURL(t)
        }, 30 * 1000)
      })
    },
    fileView(filePath) {
      this.urlList = []
      const typeName = filePath.split('.')[1]
      const imgType = ['jpg', 'jpeg', 'png', 'gif']
      const openViewType = ['pdf', 'doc', 'docx', 'xlsx', 'xls']
      if (imgType.includes(typeName)) {
      // 图片预览
        this.showViewer = true
        const picUrl = process.env.VUE_APP_IMG_PREFIX + '/' + filePath
        this.urlList.push(picUrl)
      } else if (openViewType.includes(typeName)) {
        // word,excel预览
        window.open(`${process.env.VUE_APP_OFFICE_PREFIX}?src=` + process.env.VUE_APP_IMG_PREFIX + typeName)
      } else {
        this.$message.warning('该文件类型不支持预览')
      }
    },
    // 关闭查看器
    closeViewer() {
      this.showViewer = false
      this.urlList = []
    },
    realEstateConChange(val) {
      if (val.length < 1) {
        this.$set(this.form.signingRealEstateDTO, 'realEstateContractNumber', '')
        return
      }
      const { realEstateContractNumber } = val[0]
      for (const key in val[0]) {
        const ele = val[0][key]
        this.$set(this.form.signingRealEstateDTO, key, ele)
      }
      this.$set(this.form.signingRealEstateDTO, 'realEstateContractNumber', realEstateContractNumber)
    },
    async checkForm(ref) {
      if (Array.isArray(ref)) {
        const resList = []
        for (let i = 0; i < ref.length; i++) {
          const ele = ref[i]
          this.$refs[ele].validate((valid) => {
            if (valid)resList.push(true)
            else resList.push(false)
          })
        }

        return resList.every(item => item === true)
      }
      return new Promise((resolve, reject) => {
        this.$refs.form.validate((valid) => {
          if (valid) {
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
    goBack(flag) {
      this.$emit('close', flag)
    },
    async confirm() {
      const refList = ['signingForm']
      const chkSuccess = await this.checkForm(refList)
      if (!chkSuccess) return
      const taskId = this.row[0] ? this.row[0].id : this.row.id
      const params = {
        id: taskId,
        isSigningRealEstate: this.form.signingRealEstateDTO.isSigningRealEstate,
        signingRealEstateId: this.form.signingRealEstateDTO.realEstateConItem[0].id
      }
      this.loading = true
      try {
        const putRes = await putModelRoomInfo(params)
        if (putRes.success) {
          this.$message.success('修改成功')
          const timer = setTimeout(() => {
            this.goBack(true)
            window.clearTimeout(timer)
          }, 800)
        } else {
          this.$message.warning(putRes.msg)
        }
        this.loading = false
      } catch (error) {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.option-box{
    display: none;
  .option-icon{
    padding: 0 10px;
  }
}
.link-item{
  color: $--color-primary;
}
.file-p{
  margin:0;
  padding:0;
  display: inline-block !important;
  .xiazaiIcon{
    display:inline-block;
    margin-left:10px;
    font-size:20px;
    position: relative;
    top:2px;
    cursor: pointer;
  }
}
.el-select, .el-date-editor.el-input{
  width:100%;
}
/deep/.file-p .container{
  min-height:auto;
  height:auto;
}
/deep/ .el-upload-list__item:first-child{
  margin-top:0;
}
</style>

